package com.yenlien.traceyun.plant.service;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-05
 * @description:
 **/

@Service
public class TestRestTemplateService {

    @Autowired
    private RestTemplate restTemplate;

    public void testThrow() {
        restTemplate.getForObject("http://traceyun-usercenter/config/test", JSONPObject.class);
    }

    public Object testUser(String id) {
        return restTemplate.getForObject("http://traceyun-usercenter/user/load/" + id, JSONObject.class);
    }

    public Object testRegister(JSONObject userInfo) {
        return restTemplate.postForObject("http://traceyun-usercenter/user/register", userInfo, JSONObject.class);
    }

    public static void main(String[] args) throws ParseException {
        System.out.println(dateToStamp("20200909103946"));

        String res;
        String res2;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long("1599619199817");
        long lt2 = new Long("1599619213522");
        Date date = new Date(lt);
        Date date2 = new Date(lt2);
        res = simpleDateFormat.format(date);
        res2 = simpleDateFormat.format(date2);
        System.out.println(res + "====" + "2020-09-09 10:39:46" + "====" + res2);
    }

    public static String dateToStamp(String s) throws ParseException {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }
}
